package com.topscomm.file.service;

import java.util.Map;

import com.topscomm.file.FileProperties;
import com.topscomm.file.convert.factory.FileConvertFactoryService;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * 文件封面转换
 * 
 * @description:
 * @author: donghang
 * @date: 2021年4月6日上午10:09:53
 * @modify:
 */
@Slf4j
public class FileTitlePageFilter implements IFileProcessFilter {

	/**
	 * 
	 * @description:
	 * @param paraMap
	 * @param dataProcessChain
	 * @return
	 * @author: donghang
	 * @date: 2021年4月6日上午10:10:14
	 * @modify:
	 */
	@Override
	public boolean doProcess(Map<String, Object> paraMap, IFileProcessChain dataProcessChain) throws Exception {
		FileProperties fileProperties = (FileProperties) SpringUtil.getBean("fileProperties");
		String fileName = ConvertUtil.convertToString(paraMap.get("filename"));
		String identifier = ConvertUtil.convertToString(paraMap.get("identifier"));
		StringBuilder filePath = new StringBuilder();
		// 本地的文件
		filePath.append(fileProperties.getStorePath()).append("/").append(identifier).append("/").append(fileName);
		StringBuilder targetFilePath = new StringBuilder();
		targetFilePath.append(fileProperties.getStorePath()).append("/").append(identifier).append("/")
				.append("titlepages").toString();
		FileConvertFactoryService fileConvertFactoryService = (FileConvertFactoryService) SpringUtil
				.getBean("fileConvertFactoryService");
		// 转换封面
		fileConvertFactoryService.convertFileTitlePages(identifier, filePath.toString(), targetFilePath.toString());
		dataProcessChain.doProcess(paraMap);
		return true;
	}

}
